// 添加项目按钮点击
$("#addProjectBtn").click(function () {
    console.log($("#project_add_form").serialize());
    $.ajax({
        url: "/flytest/proj/project",
        type: "post",
        data: $("#project_add_form").serialize(),
        success: function (result) {
            console.log(result);
            if (result.msg === '200') {
                window.location.href = "/flytest/proj/project_view"
            }
        }
    });
});

function setUpdateModalValue(projectName) {
    $.ajax({
        url: "/flytest/proj/project?projectName=" + projectName,
        type: "get",
        dataType: "json",
        success: function (result) {
            console.log(result.project);
            $("#projectId_u").val(result.project.projectId);
            $("#projectName_u").val(result.project.projectName);
            $("#description_u").val(result.project.description);
            $("#creator_u").val(result.project.user.email);
            $("#statusSelect").val(result.project.status);
        }
    });
}

$("#updateProjectBtn").click(function () {
    $.ajax({
        url: "/flytest/proj/project",
        type: "put",
        data: $("#project_update_form").serialize(),
        dataType: "json",
        success: function (result) {
            console.log(result);
            if (result.code === '200') {
                window.location.href = "/flytest/proj/project_view"
            } else {
                swal("未知错误请联系管理员");
            }
        }
    });
});

function deleteProjectBtnClicked(projectId) {
    bootbox.confirm({
        message: "确认删除吗？",
        buttons: {
            confirm: {
                label: 'Yes',
                className: 'btn-success'
            },
            cancel: {
                label: 'No',
                className: 'btn-danger'
            }
        },
        callback: function (result) {
            if (result) {
                $.ajax({
                    url: "/flytest/proj/project?projectId=" + projectId,
                    type: "delete",
                    dataType: "json",
                    success: function (result) {
                        if (result.code === "200") {
                            window.location.href = "/flytest/proj/project_view"
                        } else {
                            swal("删除失败，请联系管理员")
                        }
                    }
                })
            }
        }
    });

}